package com.youxuan.controller;

import com.youxuan.pojo.entity.Order;
import com.youxuan.pojo.entity.ResponseResult;
import com.youxuan.pojo.vo.AddOrderParamsVo;
import com.youxuan.pojo.vo.OrderDetailVo;
import com.youxuan.pojo.vo.OrderItemVo;
import com.youxuan.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Api(tags = "订单")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("用户订单列表")
    @ApiImplicitParams(@ApiImplicitParam(name = "uid",value = "用户id",required = true))
    @GetMapping("/list")
    public ResponseResult<List<OrderItemVo>> getList(Long uid){
        return orderService.getList(uid);
    }

    @ApiOperation("全部订单列表")
    @GetMapping("/allList")
    public ResponseResult<List<OrderItemVo>> getList(){
        return orderService.getList();
    }

    @ApiOperation("获取订单详情")
    @ApiImplicitParams(@ApiImplicitParam(name = "orderCode",value = "订单编号",required = true))
    @GetMapping("/detail")
    public ResponseResult<OrderDetailVo> getOrderDetailInfo(String orderCode) {
        return ResponseResult.okResult(orderService.getOrderDetailByOid(orderCode));
    }

    @PostMapping("/add")
    @ApiOperation("新增订单")
    public ResponseResult<Order> addOrder(@RequestBody AddOrderParamsVo addOrderParamsVo) {
        Order order = orderService.addOrder(addOrderParamsVo);
        return ResponseResult.okResult(order);
    }



}
